/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generationgraphe;

import javax.swing.table.AbstractTableModel;

/**
 *
 * @author mazid
 */
public class ModelTable extends AbstractTableModel{
    private int maxLine = 100;
    private int maxColone = 50;
    private Object[][] donnees = new Object[maxLine][maxLine];
    private static ModelTable instance = new ModelTable();
    

    public Object[][] getDonnees() {
        return donnees;
    }
    
    public static ModelTable getInstance(){
        return instance;
    }
    // pour reunitialiser la table pour une nouvelle table vide
    public void changeFeuille(){
        fireTableStructureChanged();
    }
    @Override
    public int getRowCount() {
        return maxLine;
    }

    @Override
    public int getColumnCount() {
        return maxColone;
    }
    @Override
    public String getColumnName (int columnIndex) {
        return getColumnNamePerforme (columnIndex);
    }
    // renvoie le nom des colonnes a partir de columIndex +1
    private static String getColumnNamePerforme(int columnIndex) {
        if (columnIndex == 0) {
            return "";
        }
        if (columnIndex <= 26) {
            return Character.toString((char)(columnIndex+64));
        }
        return Character.toString((char)(64+(columnIndex/26)))+((char)(64+(columnIndex%26)));
    }
//    public static String getCellName (int rowIndex, int columnIndex) {
//        return getColumnNamePerforme (columnIndex)+Integer.toString(rowIndex+1);
//    }
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        if(columnIndex ==0){
            return false;
        }
        return true; //Toutes les autres cellules éditables
    }
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        //if(aValue.)
        donnees[rowIndex][columnIndex]=aValue;
        System.out.println("le valeur est : "+aValue +" row "+rowIndex+" col "+columnIndex);
        fireTableCellUpdated(rowIndex, columnIndex);
        
    }

    @Override
    public Object getValueAt(int rowIndex, int columIndex) {
        if(columIndex==0){
            return Integer.toString(rowIndex+1);
        }
        return donnees[rowIndex][columIndex];
    }
    
    
}
